<?php
require_once '../inc/basics.php';
require_once 'admin_libs.php';

if (!Core_isAdmin()) {
	require SCRIPTBASE . 'admin/login/login.php';
	exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
	<head>
		<title>CMS Admin</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
			<meta http-equiv="X-UA-Compatible" content="IE=9" />

			<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>			
			<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js" type="text/javascript"></script>

			<script src="jquery.layout.min.js" type="text/javascript" charset="utf-8"></script>
			<script src="jquery.showLoading.min.js" type="text/javascript"></script>
			<script src="../javascript/jstree/jquery.jstree.js" type="text/javascript"></script>
			<script src="../javascript/tiny_mce_3.5.7/jquery.tinymce.js" type="text/javascript"></script>
			<script src="../javascript/jquery.ui.touch-punch.min.js" type="text/javascript"></script>

			<link rel="stylesheet" type="text/css" href="main.css">
				<link rel="stylesheet" type="text/css" href="jquery-ui-1.9.1.custom.css">
					<?php
					echo Core_getScripts() . Core_getCSS();
					?>		
					<script type="text/javascript">
						
						var outerLayout, middleLayout, innerLayout;
						
						$(document).ready(function () {

							//layout frames
							outerLayout = $("body").layout({
								center__paneSelector:	".outer-center",
								north__paneSelector:	".outer-north",
								south__paneSelector:	".outer-south",
								west__paneSelector:		".outer-west",
								east__paneSelector:		".outer-east",
								west__size:				20,
								east__size:				20,
								south__size:			30,
								spacing_open:			0,
								spacing_closed:			0,
								north__spacing_open:	0,
								south__spacing_open:	0,
								center__resizable:		false,
								center__cloasable:		false,
								enableCursorHotkey:		false
							});

							middleLayout = $(".outer-center").layout({
								west__paneSelector:		".middle-west",
								center__paneSelector:	".middle-center",
								west__resizable :		true,
								west__size:				170,
								west__spacing_open:		4,
								west__spacing_closed:	8,
								togglerLength_closed:	"100%",
								enableCursorHotkey:		false
							});
							
							var innerLayoutOptions = {
								defaults: {
									spacing_open:			4,
									spacing_closed:			8, 
									resizable :				true,
									togglerLength_closed:	"100%",
									enableCursorHotkey:		false,
									initClosed:				false
								},
								west:	{
									paneSelector:		".inner-west",
									size:				150
								},
								center:	{paneSelector:	".inner-center"},
								east:	{
									paneSelector:	".inner-east",
									size:			150
								}
							};

							innerLayout = $(".middle-center").layout( innerLayoutOptions );

							//load menu
							$("#middle-west").showLoading();
							$("#menu").load("menu.php", function(){
								$('#menu li:has(ul)')
								.click(function(event){
									if(this == event.target){
										$(this).children().toggle();
										$(this).css('background', ($(this).children().is(':hidden')) ? 'url(images/closed.png) 0 3px no-repeat' : 'url(images/open.png) 0 3px no-repeat');
									}
								})
								.css('cursor','pointer')
								.click();
								$("#middle-west").hideLoading();
								
								//menu actions
								$('#menu li:not(:has(ul))').click(function(e){
									var toLoad = $(this).attr('id');
									var $container = $(".middle-center"),   
									layout = $container.data("layout");
									if ( layout ){
										layout.destroy();
									}
									//load content
									$("#content").empty();
									$("#content").showLoading().load(toLoad + '.php', function(resonse, status, xhr){
										if (xhr.status == "401") {	//no permission
											$("#content").hideLoading();
											notify('U heeft onvoldoende rechten voor deze actie','ui-state-error',e);
										}else if(xhr.status != '200'){	//page not found
											$("#content").hideLoading();											
											notify('Oeps! Deze pagina bestaat niet!', 'ui-state-highlight',e);
										}else{
											//succes
											innerLayout = $container.layout( innerLayoutOptions );
											$("button").button();
											$("#content").hideLoading();										
										}
									});
									return false;
								});	
					
							}); //end load menu

							function notify( msg, cl, event ) {
									if(!event) pos = { my: "center", at: "center", of: window };
									else pos = { my: "left+5 bottom-5", at: "right top", of: event };
									$( "<div>" )
									.appendTo( document.body )
									.text( msg )
									.addClass(cl)
									.addClass( "notification ui-corner-bottom" )
									.position(pos)
									.show({
										effect: "scale"
									})
									.delay( 2000 )
									.hide({
										effect: "scale"
									}, function() {
										$( this ).remove();
									});
							}
							
							//notify('test');

							$("button").button();
				
						});
					</script>

					</head>
					<body>
						<div class="outer-center">
							<div id="content" class="middle-center">
								<!--
								<div class="inner-west">
									<p>inner-west</p>
								</div>
								-->
								<div class="inner-center">
									<p>inner-center</p>
								</div>
								<!--
								<div class="inner-east">
									<p>inner-east</p>
								</div>
								-->

							</div>

							<div class="middle-west" id="middle-west">
								<div class="middle-west-content" id="menu"></div>
							</div>

						</div>
						<div class="outer-north">
							<div id="textContainer">
								<span id="textCMS"><img src="images/cms_text.gif" width="44" height="15" alt="" /></span><span id="textVersion">0.6.0</span><br />

								<span id="textSite">CMS testsite</span><span id="textLogin">Je bent ingelogd als: <?php echo $_SESSION['userdata']['email'] ?> | <a href="../inc/logout.php?redirect=<?php echo $_SERVER['PHP_SELF']; ?>">Uitloggen</a></span>
							</div>
						</div>
						<div class="outer-west"></div>
						<div class="outer-east"></div>
						<div class="outer-south"></div>
					</body>
					</html>
